#ifndef RECORDTASK_H
#define RECORDTASK_H

#include "libs/base/task/task.h"
#include "libs/core/model/liveinfo.h"
#include <QDateTime>

class LiveRecorder;
class StreamRecorderWithFailover;

class RecordTask : public yc::Task
{
    Q_OBJECT
public:
    RecordTask(LiveRecorder* recorder, int attention, QObject* parent = nullptr);
    ~RecordTask();

    int attention() const { return attention_; }
    void stop();

Q_SIGNALS:
    void positionChanged(qint64 pos);
    void recordFinished(const QString& filename, qint64 duration);

private:
    void startImpl() override;
    void terminateImpl() override;
    void getPresenterStatus(int id);
    void getActiveLive(int id);
    bool startRecord(int live_id);
    void getLiveInfo();
    void addLive(const yc::LiveInfo& live_info);
    void startStreamRecord(const yc::LiveInfo& live_info);
    void onRecordFinished(const QString& filename, qint64 duration);

    LiveRecorder* recorder_;
    int attention_;
    int request_id_ = 0;
    QDateTime start_time_;
    StreamRecorderWithFailover* stream_recorder_ = nullptr;
};

#endif // RECORDTASK_H
